package com.szholly.pro.watergas_server.ps.service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import com.szholly.data.general.GlobalParameter;
import com.szholly.data.general.ITable;
import com.szholly.data.general.ITableFactory;
import com.szholly.data.general.RowBase;
import com.szholly.pro.watergas_server.common.data.DataUtil;
import com.szholly.pro.watergas_server.common.util.RedisDbExecute;
import com.szholly.pro.watergas_server.common.util.RedisHelper;
import com.szholly.pro.watergas_server.common.web.MessageException;
import com.szholly.utils.spring.SpringBeanFactory;
import com.szholly.utils.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RemoteService {
	
	// 命令描述集合
	protected static HashMap<String, String> opcStatusMap = null;
	
	@Autowired
	protected DomainService domService;
	
	@Autowired
	protected DataReportService dataReportService;
	
	private static RemoteService _instance;
	
	public RemoteService(){
		_instance = this;
	}
	
	/**
	 * 获取实例，暴露给websocket使用
	 * gislin
	 * 2016年3月19日
	 * @return
	 */
	public static RemoteService getInstance(){
		return _instance;
	}
	
	/**
	 * 获取站点的设备状态
	 * gislin
	 * 2016年5月4日
	 * @param mn
	 * @return
	 */
	public HashMap<String, HashMap<String,String>> getDeviceInfo(String mn){
		
		String keyPrix = "stationInfo:"+mn+":deviceInfo:*_BAND";
		Set<String> keySet = RedisDbExecute.queryKeys(keyPrix);
		
		HashMap<String, HashMap<String,String>> deviceInfos = new HashMap<>();
		
		for(String key : keySet){
			String deviceCode = key.replace("stationInfo:"+mn+":deviceInfo:", "").replace("_BAND", "");
			HashMap<String,String> deviceInfo = new HashMap<>();
			String bandName = RedisHelper.getInstance().getDeviceBandText(mn, deviceCode);
			String processText = RedisHelper.getInstance().getDeviceProcessText(mn, deviceCode);
			String statusText = RedisHelper.getInstance().getDeviceStatusText(mn, deviceCode);
			String errorText = RedisHelper.getInstance().getDeviceErrorText(mn, deviceCode);
			deviceInfo.put("bandName", bandName);
			deviceInfo.put("process", processText);
			deviceInfo.put("status", statusText);
			deviceInfo.put("error", errorText);
			deviceInfos.put(deviceCode, deviceInfo);
		}
		return deviceInfos;
	}
	
	/**
	 * 获取站点实时数据
	 * @param params
	 * @param pageInfo
	 * @return
	 * @throws Exception
	 */
	public static HashMap<String, RowBase> getStationRealTimeData(String mn) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat dateParse = new SimpleDateFormat("yyyyMMddHHmmss");
		String keyPrix = "stationInfo:"+mn+":deviceInfo:";
		Set<String> keySet = RedisDbExecute.queryKeys(keyPrix+"*");
		
		String currentPoll = null;
		HashMap<String, RowBase> realTimeDataMap = new HashMap<>();
		RowBase row = null;		
		
		for(String key : keySet){
			String value = RedisDbExecute.getString(key);
			String oldValue = value.replace(".0", "");
			String simpleKeyName = key.replace(keyPrix, "");
			String poll = null;
			String pollName ;
			String unit;//单位
			String valueKey = null;// 传到前端的key值
			if(simpleKeyName.indexOf("_") > -1){
				
				if(simpleKeyName.indexOf("MEAS_NORMAL") > -1){
					poll = simpleKeyName.replace("_MEAS_NORMAL", "");
					pollName = translationPollDict(poll);
					valueKey = "MEAS_NORMAL";
				}
				else{
					poll = simpleKeyName.substring(0,simpleKeyName.lastIndexOf("_"));
					pollName = translationPollDict(poll);
					valueKey = simpleKeyName.substring(simpleKeyName.lastIndexOf("_")+1);
				}
			}
			else{
				poll = simpleKeyName;
				pollName = translationPollDict(poll);
				valueKey = "MEAS";
			}
			
			// 没有记录的参数不翻译不处理
			if(pollName == null || pollName.equals("")){
				continue;
			}
			
			if(simpleKeyName.indexOf("TIME") > -1){
				try {
					value = dateFormat.format(dateParse.parse(value));
				} catch (Exception e) {
					
				}
			}
			
			if(simpleKeyName.indexOf("MEAS") > -1){
				try {
					BigDecimal doubleValue  =  new BigDecimal(value);
					value = doubleValue.setScale(3, BigDecimal.ROUND_HALF_EVEN).doubleValue()+"";
				} catch (Exception e) {
					
				}
			}
	
			if(simpleKeyName.indexOf("B01TOTAL") > -1){
				try {
					BigDecimal doubleValue  =  new BigDecimal(value);
					value=doubleValue.toPlainString();
				} catch (Exception e) {
					
				}
			}
			
			unit = getPollUnit(poll);
			
			if(!poll.equals(currentPoll)){
				row = new RowBase();
				realTimeDataMap.put(poll, row);
				currentPoll = poll;
			}
			
			Double alarmUp = RedisHelper.getInstance().getPollAlarmUp(mn, poll);
			Double alarmDown = RedisHelper.getInstance().getPollAlarmDown(mn, poll);
			
			row.setValue(valueKey, value);
			row.setValue(valueKey+"_old", oldValue);
			row.setValue("pollName",pollName);
			row.setValue("alarmUp",alarmUp);
			row.setValue("alarmDown",alarmDown);
			row.setValue("poll", poll);
			row.setValue("UNIT", unit);
		}
		return realTimeDataMap;
	}
	
	/**
	 * 批量发送命令，格式：pollId=011,attr=CLEAR,value=1;pollId=001,attr=CLEAR,value=0;
	 * gislin
	 * 2016年1月7日
	 * @param mn
	 * @param deviceId 参数仪器编号
	 * @param ordersStr
	 * @return 返回请求编号列表
	 */
	public List<String> sendOrders(String mn,String deviceId,String ordersStr){
		List<HashMap<String, String>> orders = ParseOrderStr(ordersStr);
		List<String> qns = new ArrayList<>();
		int i = 0;
		for(HashMap<String, String> order : orders){
			String pollId = order.get("PolID");
			String attr = order.get("Attr");
			String value = order.get("Value");
			String qn = send3011Order(mn,deviceId, pollId, attr, value,i);
			qns.add(qn);
			i++;
		}
		
		return qns;
	}
	
	/**
	 * 获取站房信息
	 * gislin
	 * 2016年4月25日
	 * @param mn
	 * @return
	 */
	public List<RowBase> getStationHouseData(String mn){
		List<RowBase> result = RedisHelper.getInstance().getStationHouseData(mn);
		return result;
	}
	
	/**
	 * 给现场机发送远程控制命令
	 * gislin
	 * 2015年12月31日
	 * @param mn 设备编号牌
	 * @param deviceId 参数仪器id,
	 * @param pollId 参数名称，依据数据传输客户端的配置文件来定
	 * @param attr 要控制的变量名称,依据数据传输客户端的配置文件来定
	 * @param value 变量要设置成的值
	 * @param index 请求顺序，批量请求的时候用于确保请求编号唯一
	 * @return 返回请求编号
	 */
	public String send3011Order(String mn,String deviceId,String pollId,String attr,String value,int index){
		String qn = getQn(index);
		String cn = "3011"; // 远程命令编号是3011
		String cp = "Attr="+attr+",Value="+value;
		String pollName = translationPollDict(pollId);
		String commandDesc = translationOrderDict(attr);
		if(pollName != null ){
			commandDesc += ","+pollName;
		}
		
		if(pollId != null && !pollId.equals("")){
			cp = "PolID="+pollId+","+cp;
		}
		
		String sql = " INSERT INTO REMOVE_CONTROL_ORDER(GUID,MN,CN,CP,QN,ORDER_DESC) VALUES(@GUID,@MN,@CN,@CP,@QN,@ORDER_DESC)";
		List<GlobalParameter> pc = new ArrayList<>();
		pc.add(new GlobalParameter("GUID",UUID.randomUUID().toString()));
		pc.add(new GlobalParameter("MN",mn));
		pc.add(new GlobalParameter("CN",cn));
		pc.add(new GlobalParameter("CP",cp));
		pc.add(new GlobalParameter("QN",qn));
		pc.add(new GlobalParameter("ORDER_DESC",commandDesc));
		DataUtil.ExecuteUpdateSql(sql, pc);
		
		// 如果有参数设备Id，则更新DEVICE_ORDER表的LAST_ORDER_QN字段，为其他业务判断对应命令是否执行作为依据
		if(deviceId != null && !deviceId.trim().equals("")){
			String updateOrderStatusSql = " UPDATE DEVICE_ORDER SET LAST_ORDER_QN = @QN WHERE DEVICE_ID = @deviceId and ORDER_ID = @attr ";
			pc.clear();
			pc.add(new GlobalParameter("deviceId",deviceId));
			pc.add(new GlobalParameter("QN",qn));
			pc.add(new GlobalParameter("attr",attr));
			DataUtil.ExecuteUpdateSql(updateOrderStatusSql, pc);
		}
		
		// 如果是更新系统模式，把数采仪表的“SYS_M_CHANGING”改为1，表示状态改变中……
		if(attr.equals("SYS_MODEL")){
			String updateSql = " UPDATE BC_COLLECTION_INFO SET SYS_M_QN = '"+qn+"' WHERE DEVICE_NUM = @MN ";
			pc.clear();
			pc.add(new GlobalParameter("MN",mn));
			DataUtil.ExecuteUpdateSql(updateSql, pc);
		}
		
		return qn;
	}
	/**
	 * 给现场机发送远程控制命令
	 * wangl
	 * @param mn 数采仪编号
	 * @param cn 数据类型编号
	 * @param cp 请求条件
	 * @note 描述
	 */
	public void sendOrder(String mn,String cn,String cp,int index,String note){
		String qn = getQn(index);
		String sql = " INSERT INTO REMOVE_CONTROL_ORDER(GUID,MN,CN,CP,QN,ORDER_DESC) VALUES(@GUID,@MN,@CN,@CP,@QN,@ORDER_DESC)";
		List<GlobalParameter> pc = new ArrayList<>();
		pc.add(new GlobalParameter("GUID",UUID.randomUUID().toString()));
		pc.add(new GlobalParameter("MN",mn));
		pc.add(new GlobalParameter("CN",cn));
		pc.add(new GlobalParameter("CP",cp));
		pc.add(new GlobalParameter("QN",qn));
		pc.add(new GlobalParameter("ORDER_DESC",note));
		DataUtil.ExecuteUpdateSql(sql, pc);
	}
	
	/**
	 * 生成请求编号
	 * gislin
	 * 2015年11月16日
	 * @return
	 */
	protected synchronized String getQn(int index){
		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmssSSSS");
		String qn = sf.format(new Date())+index;
		return qn;
	}
	
	/**
	 * 把pollId=011,attr=CLEAR,value=1;pollId=001,attr=CLEAR,value=0;处理成List<HashMap<String, String>>
	 * gislin
	 * 2016年1月7日
	 * @param ordersStr
	 * @return
	 */
	protected List<HashMap<String, String>> ParseOrderStr(String ordersStr){
		List<HashMap<String, String>> orderList = new ArrayList<>();
		
		String[] orders = ordersStr.split(";");
		for(String order : orders){
			HashMap<String, String> orderInfoMap = new HashMap<>();
			String[] orderInfos = order.split(",");
			for(String infoItem : orderInfos){
				orderInfoMap.put(infoItem.split("=")[0],infoItem.split("=")[1]);
			}
			orderList.add(orderInfoMap);
		}
		
		return orderList;
	}
	
	/**
	 * 获取数采仪设备编号
	 * gislin
	 * 2015年11月13日
	 * @param
	 * @param
	 * @return
	 */
	public String getDataCollectDevMNByStationId(String stationId){
		
		String getMNInfoSql = " SELECT DEVICE_NUM FROM BC_COLLECTION_INFO WHERE SITE_ID = '"+stationId+"' and rownum=1";
		Object mnObj = DataUtil.getScale(getMNInfoSql, null);
		String mn = mnObj == null ?null:mnObj.toString();
		return mn;
	}
	
	/**
	 * 根据获取指定站点下，所有设备对应的远程控制命令，以及实时数据
	 * gislin
	 * 2016年1月5日
	 * @param stationId
	 * @return
	 */
	public HashMap<String, HashMap<String,Object>> getMonitorDeviceOrders(String stationId,String mn){
		
		// DEVICE_ORDER设备命令关联表
		// DATA_DEFULATDOMAIN字典表
		// MONITOR_EQUIPMENT检测设备表
		// MONITOR_DATA_REALTIME参数实时数据表
		// REMOVE_CONTROL_ORDER命令发送表，里面有每条命令执行的结果
		// is_order_time_good的作用：如果一个命令发送了，那么在接下来的两个小时内不能再执行控制
		String orderSql =" select  me.monitor_pollutants PARMNAME,\n" + 
						"          me.guid deviceId,\n"+
						"          dd.s_domaincode order_code,\n" + 
						"          dd.s_domaincaption order_desc,\n" + 
						"          'TRUE' ORDER_ENABLE,\n"+
						"          nvl(rco.STATUS,'2') order_status\n" + 						
						"from BC_SITE_DEVICE_RPT me\n" +
						" left join DEVICE_ORDER do on do.DEVICE_ID = me.guid\n" + 
						" LEFT JOIN DATA_DEFULATDOMAIN dd ON do.order_id = dd.s_domaincode and dd.s_domainname = 'REMOTE_CONTROL_ORDER'\n" + 
						" left join REMOVE_CONTROL_ORDER rco ON rco.qn = do.LAST_ORDER_QN\n"+
						"WHERE me.monitor_point = @stationId ORDER BY me.monitor_pollutants,dd.s_domaincode\n" ;
		
		String pollSql = "select sp.name,me.monitor_pollutants EQ_CODE,me.guid from BC_SITE_POLL sp\n" +
						"       inner join BC_SITE_DEVICE_RPT  ME ON sp.device_id = me.guid\n" + 
						"       where sp.site_id = @stationId order by me.monitor_pollutants";
		
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		parms.add(new GlobalParameter("stationId",stationId));
		
		ITableFactory tableFactory = (ITableFactory) SpringBeanFactory.getBean("TableFactory");
		ITable table = tableFactory.openTable("POLLDATA");
		List<RowBase> orderList = DataUtil.getSelectRows(orderSql, parms, table);
		List<RowBase> pollList = DataUtil.getSelectRows(pollSql, parms);
		
		// 组织数据，方便前端显示数据
		HashMap<String, HashMap<String,Object>> paramOrders = new HashMap<>();
		String currentParamName = "";
		List<RowBase> currentOrderList = null;
		List<RowBase> currentPollList = new ArrayList<>();
		
		for(RowBase rowBase : orderList) {
			String deviceCode = rowBase.getSafeString("PARMNAME");
			String paramName = RedisHelper.getInstance().translationDictValue("检测设备代号", deviceCode);
			
			//如果设备编号没有对应的翻译，则略过
			if(paramName == null ){
				continue;
			}
			
			if(!paramName.equals(currentParamName)){
				HashMap<String,Object> deviceInfo = new HashMap<>();
				currentOrderList = new ArrayList<>();
				deviceInfo.put("orderList",currentOrderList);
				deviceInfo.put("paramName",paramName);
				String bandName = RedisHelper.getInstance().getDeviceBandText(mn, deviceCode);
				String processText = RedisHelper.getInstance().getDeviceProcessText(mn, deviceCode);
				String statusText = RedisHelper.getInstance().getDeviceStatusText(mn, deviceCode);
				String errorText = RedisHelper.getInstance().getDeviceErrorText(mn, deviceCode);
				deviceInfo.put("bandName", bandName);
				deviceInfo.put("process", processText);
				deviceInfo.put("status", statusText);
				deviceInfo.put("error", errorText);
				paramOrders.put(deviceCode, deviceInfo);
				currentParamName = paramName;
			}
			currentOrderList.add(rowBase);
		}
		
		String currentEQCode = "";
		
		for(RowBase rowBase : pollList){
			String eqCode = rowBase.getSafeString("EQ_CODE");//设备编号
			
			if(!eqCode.equals(currentEQCode)){
				currentPollList = new ArrayList<>();
				HashMap<String,Object> deviceInfo = paramOrders.get(eqCode);
				if(deviceInfo == null){
					continue;
				}
				deviceInfo.put("pollList",currentPollList);
				currentEQCode = eqCode;
			}
			if(currentPollList == null){
				System.out.println();
			}
			currentPollList.add(rowBase);
		}
		
		return paramOrders;
	}
	
	/**
	 * 获取站点下的仪器列表，用于远程质控，需要设置每个仪器的质控参数
	 * gislin
	 * 2016年4月19日
	 * @param stationId
	 * @return
	 */
	public List<RowBase> getMonitorDeviceByStation(String stationId){
		
		String sql = " SELECT dd.s_domaincode code,dd.s_domaincaption text from BC_SITE_DEVICE_RPT me "
					+ " inner join data_defulatdomain dd on me.monitor_pollutants = dd.s_domaincode and dd.s_domainname = '检测设备代号' "
					+ " where me.monitor_point = @stationid ";
		List<GlobalParameter> pc = new ArrayList<>();
		
		pc.add(new GlobalParameter("stationid", stationId));
		List<RowBase> rows = DataUtil.getSelectRows(sql, pc);
		//过滤部分质控参数，包括挥发酚、VOC、流量、五参数水箱
		for(int i=0;i< rows.size();i++) {
			RowBase row = new RowBase();
			row = rows.get(i);
			String TEXT = row.getSafeString("TEXT");
			if("挥发酚".equals(TEXT)||"五参数水箱".equals(TEXT)||"VOC".equals(TEXT)||"流量".equals(TEXT)) {
				rows.remove(i);
			}
		}
		return rows;
	}
	
	/**
	 * 获取某个参数的质控配置
	 * gislin
	 * 2016年4月21日
	 * @param mn
	 * @param pollName
	 * @return
	 */
	public HashMap<String, String> getQualityConfig(String mn,String pollName){
		HashMap<String, String> result = RedisHelper.getInstance().getQualityConfig(mn, pollName);
		return result;
	}
	
	/**
	 * 获取指定设备对应的远程控制命令，以及实时数据
	 * gislin
	 * 2016年1月5日
	 * @param deviceId
	 * @return
	 */
	public List<RowBase> getMonitorDeviceOrdersByDeviceId(String deviceId){
		
		// DEVICE_ORDER设备命令关联表
		// DATA_DEFULATDOMAIN字典表
		// MONITOR_EQUIPMENT检测设备表
		// MONITOR_DATA_REALTIME参数实时数据表
		String sql = " SELECT mdr.status,\n "
				+ " mdr.process,\n"
				+ " mdr.error,\n"
				+ " mdr.rtd,\n"
				+ " dd.s_domaincode,\n"
				+ " dd.s_domaincaption,\n"
				+ " case when me.GUID is null then '0' else '1' end isChecked \n"
				+ " FROM DATA_DEFULATDOMAIN dd \n"
				+ " LEFT JOIN DEVICE_ORDER do ON do.order_id = dd.s_domaincode AND do.device_id = @deviceId \n"
				+ " left join BC_SITE_DEVICE_RPT  me ON do.DEVICE_ID = me.guid \n"
				+ " LEFT JOIN MONITOR_DATA_REALTIME mdr ON mdr.parmname = me.monitor_pollutants and me.data_num = mdr.mn \n "
				+ " WHERE dd.s_domainname = 'REMOTE_CONTROL_ORDER'";		
		List<GlobalParameter> params = new ArrayList<>();
		params.add(new GlobalParameter("deviceId", deviceId));
		ITableFactory tableFactory = (ITableFactory) SpringBeanFactory.getBean("TableFactory");
		ITable table = tableFactory.openTable("POLLDATA");
		List<RowBase> list = DataUtil.getSelectRows(sql, params, table);
		
		return list;
	}
	
	/**
	 * 更新指定设备的命令集，先删除再插入
	 * gislin
	 * 2016年1月5日
	 * @param deviceId
	 * @param
	 * @throws MessageException 
	 */
	public void updateDeviceOrders(String deviceId,String ordersStr) throws MessageException {
		DataUtil.beginTransaction();
		try {
			String deleteSql = " DELETE FROM DEVICE_ORDER WHERE DEVICE_ID = @deviceId ";
			List<GlobalParameter> params = new ArrayList<>();
			params.add(new GlobalParameter("deviceId", deviceId));
			DataUtil.ExecuteUpdateSql(deleteSql, params);
			
			String insertSql = " INSERT INTO DEVICE_ORDER(GUID,DEVICE_ID,ORDER_ID) VALUES(SYS_GUID(),@deviceId,@orderId) ";
			String[] orders = ordersStr.split(",");
			for(String order : orders){
				params.clear();
				params.add(new GlobalParameter("deviceId", deviceId));
				params.add(new GlobalParameter("orderId", order));
				DataUtil.ExecuteUpdateSql(insertSql, params);
			}
			DataUtil.commitTransaction();
		} catch (Exception e) {
			DataUtil.commitTransaction();
			throw new MessageException(e.getMessage());
		}
	}
	
	/**
	 * 获取站点污染物列表
	 * gislin
	 * 2016年3月1日
	 * @param stationId
	 */
	public List<RowBase> getStationPolls(String stationId){
		String sql = "select dd.s_domaincode code,dd.s_domaincaption text from BC_SITE_POLL sp\n" +
						"       left join data_defulatdomain dd on sp.name = dd.s_domaincode AND dd.S_DOMAINNAME = 'MONITOR_PARAM' \n" +
						" where site_id = @SITEID";

		List<GlobalParameter> pc = new ArrayList<>();
		pc.add(new GlobalParameter("SITEID", stationId));
		List<RowBase> pollList = DataUtil.getSelectRows(sql, pc);
		return pollList;
	}
	/**
	 * 管路切换日志记录
	 * @param
	 * @param
	 * @throws MessageException
	 */
	public void insertSystemOperationLog(Map<String, String> params) throws MessageException{
		try {
			List<GlobalParameter> listParam = new ArrayList<>();
			String insertSql = " INSERT INTO SYSTEM_OPERATION_LOG t (GUID,OPERATOR,OPERATE_TIME,OPERATE_ITEM,MN) VALUES(SYS_GUID(),@OPERATOR,SYSDATE,@OPERATE_ITEM,@MN) ";
			
			if (params.containsKey("MN")) {
				listParam.add(new GlobalParameter("MN", params.get("MN")));
			}
			
			if (params.containsKey("STATION_STATUS")&& params.containsKey("NAME")) {
				String item = "";
				if("3".equals(params.get("STATION_STATUS"))) {
					item="开启";
				} else {
					item="关闭";
				}
				item+=params.get("NAME");
				listParam.add(new GlobalParameter("OPERATE_ITEM", item));
			}
			if (params.containsKey("operator")) {
				listParam.add(new GlobalParameter("OPERATOR", params.get("operator")));
			}
			DataUtil.ExecuteUpdateSql(insertSql, listParam);
		} catch (Exception e) {
			throw new MessageException(e.getMessage());
		}
	}
	
	/**
	 * 定时，轮询、手动模式切换日志记录
	 * @param
	 * @param
	 * @throws MessageException
	 */
	public void insertGuanLuChangeLog(String MN,String OPERATION_ITEM,String operatorStr) throws MessageException{
		try {
			List<GlobalParameter> listParam = new ArrayList<>();
			if (!StringUtils.IsNullOrEmpty(operatorStr)) {
				listParam.add(new GlobalParameter("OPERATOR", operatorStr));
			}
			if (!StringUtils.IsNullOrEmpty(MN)) {
				listParam.add(new GlobalParameter("MN", MN));
			}
			if (!StringUtils.IsNullOrEmpty(OPERATION_ITEM)) {
				listParam.add(new GlobalParameter("OPERATE_ITEM", OPERATION_ITEM));
			}
			String insertSql = " INSERT INTO SYSTEM_OPERATION_LOG t (GUID,OPERATOR,OPERATE_TIME,OPERATE_ITEM,MN) VALUES(SYS_GUID(),@OPERATOR,SYSDATE,@OPERATE_ITEM,@MN) ";
			DataUtil.ExecuteUpdateSql(insertSql, listParam);
		} catch (Exception e) {
			throw new MessageException(e.getMessage());
		}
	}
	
	public void insertSysCycleSetLog(String MN,String OPERATION_ITEM,String operator)throws Exception{
		try {
			List<GlobalParameter> listParam = new ArrayList<>();
			if (!StringUtils.IsNullOrEmpty(MN)) {
				listParam.add(new GlobalParameter("MN", MN));
			}
			if (!StringUtils.IsNullOrEmpty(OPERATION_ITEM)) {
				listParam.add(new GlobalParameter("OPERATE_ITEM", OPERATION_ITEM));
			}
			if (!StringUtils.IsNullOrEmpty(operator)) {
				listParam.add(new GlobalParameter("OPERATOR", operator));
			}
			String insertSql = " INSERT INTO SYSTEM_OPERATION_LOG t (GUID,OPERATOR,OPERATE_TIME,OPERATE_ITEM,MN) VALUES(SYS_GUID(),@OPERATOR,SYSDATE,@OPERATE_ITEM,@MN) ";
			DataUtil.ExecuteUpdateSql(insertSql, listParam);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	/**
	 * 翻译远程控制命令
	 * gislin
	 * 2016年4月22日
	 */
	private static String  translationOrderDict(String code){
		String text = RedisHelper.getInstance().translationDictValue("remote_control_order",code);
		return text;
	}	
	
	/**
	 * 翻译污染物
	 * gislin
	 * 2016年4月22日
	 * @return
	 */
	private static String translationPollDict(String code){
		String text = RedisHelper.getInstance().translationDictValue("MONITOR_PARAM",code);
		return text;
	}
	
	/**
	 * 获取污染物单位
	 * gislin
	 * 2016年4月22日
	 * @return
	 */
	private static String getPollUnit(String code){
		String text = RedisHelper.getInstance().translationDictUnit("MONITOR_PARAM",code);
		return text;
	}
}
